import 'jquery-validation';
export default class Base{
    constructor(){
        this._initValidator();
    }

    _initValidator(){
        const $form = $('#entry-form');
    const validator = $form.validate({
      rules: {
        title: {
          maxlength: 100,
          required: {
            depends () {
              $(this).val($.trim($(this).val()));
              return true;
            }
          }
        },
        body: {
          required: {
            depends () {
              $(this).val($.trim($(this).val()));
              return false;
            }
          }
        }
      },
      messages:{
          'title':'请输入标题',
          'body':'请输入内容'
      }
        

    });
    $('#entry-base-submit').click((event) => {
      if (validator.form()) {
        $(event.currentTarget).button('loading');
        $form.submit();
      }
    });
    }
}